package com.cskaoyan.service.wx;

import com.cskaoyan.bean.goods.wx.ListBean;
import com.cskaoyan.bean.home.*;
import com.cskaoyan.bean.po.*;
import com.cskaoyan.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: WxHomeServiceImpl
 * Description:
 * date: 2022/6/8 18:15
 *
 * @author bruce
 * @since JDK 8
 */
@Service
public class WxHomeServiceImpl implements WxHomeService {

    @Autowired
    MarketGoodsMapper marketGoodsMapper;

    @Autowired
    MarketCategoryMapper marketCategoryMapper;

    @Autowired
    MarketCouponMapper marketCouponMapper;

    @Autowired
    MarketAdMapper marketAdMapper;

    @Autowired
    MarketBrandMapper marketBrandMapper;

    @Autowired
    MarketTopicMapper marketTopicMapper;

    @Autowired
    MarketSystemMapper marketSystemMapper;

    @Override
    public WxHomeListData queryIndex() {
        Integer news = marketSystemMapper.selectKeyValue("market_wx_index_new");
        List<ListBean> newGoods = marketGoodsMapper.selectNewGoods(news);

        List<WxHomeCoupon> couponList = marketCouponMapper.selectCoupon();

        List<WxHomeCategory> channel = marketCategoryMapper.selectCategory(10);

        List<WxHomeAd> banner = marketAdMapper.selectAd();

        Integer brand = marketSystemMapper.selectKeyValue("market_wx_index_brand");
        List<WxHomeBrand> brandList = marketBrandMapper.selectBrand(brand);

        Integer hot = marketSystemMapper.selectKeyValue("market_wx_index_hot");
        List<ListBean> hotGoods = marketGoodsMapper.selectHotGoods(hot);

        Integer topic = marketSystemMapper.selectKeyValue("market_wx_index_topic");
        List<WxHomeTopic> topicList = marketTopicMapper.selectTopic(topic);

        //todo
        Integer limit1 = marketSystemMapper.selectKeyValue("market_wx_catlog_list");
        Integer limit2 = marketSystemMapper.selectKeyValue("market_wx_catlog_goods");
        List<FloorGoodsListBean> floorGoodsList = marketCategoryMapper.selectfloorGoodsList(limit1);
        for (FloorGoodsListBean floorGoodsListBean : floorGoodsList) {
            ArrayList<ListBean> listBeans = new ArrayList<>();
            Integer id = floorGoodsListBean.getId();
            List<ListBean> listBeans1 = marketCategoryMapper.selectCatlogGoods(id,limit2);
            listBeans.addAll(listBeans1);
            floorGoodsListBean.setGoodsList(listBeans);
        }

        return WxHomeListData.data(newGoods ,couponList,channel,banner,brandList,hotGoods,topicList,floorGoodsList);
    }
}
